import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { DataEvent } from "../../../events/DataEvent";
import { Cache } from "../../../cache/Cache";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { FriendStyle } from "../../friends/FriendStyle";
import { MsgManager } from "../../../manager/MsgManager";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../../common/alertwins/CheckBoxWin";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemExInfo } from "../../../resource/info/ItemExInfo";
import { Tooltip } from "../../common/tooltip/Tooltip";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { MountCraveColorPicker } from "../mount/MountCraveColorPicker";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { PublicMessageConfig } from "../../../resource/PublicMessageConfig";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { _curIdata } from "../../../../../this/_curIdata";
import { _curColorNum } from "../../../../../this/_curColorNum";
import { _curGlowNum } from "../../../../../this/_curGlowNum";
type int = number;
//class MountCraveWindow
    
    export  class MountCraveWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(330, 316);
            titleHeight = 30;
            title = Language.getString(70159);
            return;
        }

        protected onGloweelectHandler(arg1: DataEvent): void
        {
            this._curGlowNum = Cache.instance.pack.mountsPackCache.getCraveColorNum(arg1.data as uint);
            this.reflashTooltip();
            return;
        }

        protected onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._colorPanel.visible) 
            {
                this._colorPanel.visible = false;
            }
            if (this._glowPanel.visible) 
            {
                this._glowPanel.visible = false;
            }
            return;
        }

        protected onColorBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._colorPanel.visible = !this._colorPanel.visible;
            this._glowPanel.visible = false;
            arg1.stopImmediatePropagation();
            return;
        }

        protected onGlowBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._glowPanel.visible = !this._glowPanel.visible;
            this._colorPanel.visible = false;
            arg1.stopImmediatePropagation();
            return;
        }

        protected onInputChange(arg1: Object /* flash.events.Event */): void
        {
            this._inputTx.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, Cache.instance.pack.mountsPackCache.getCraveColor(this._curColorNum)));
            return;
        }

        protected changeSearchHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            if (arg1.type == flash.events.FocusEvent.FOCUS_IN && this._inputTx.text == Language.getString(70162)) 
            {
                this._inputTx.text = "";
                this._inputTx.setStyle("textFormat", new GTextFormat(FontUtil.songtiName, 12, Cache.instance.pack.mountsPackCache.getCraveColor(this._curColorNum)));
            }
            if (arg1.type == flash.events.FocusEvent.FOCUS_OUT && this._inputTx.text == "") 
            {
                this._inputTx.text = Language.getString(70162);
                this._inputTx.setStyle("textFormat", FriendStyle.textFormatOffline);
            }
            return;
        }

        protected onBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=false;
            var loc3=arg1.target;
            switch (loc3) 
            {
                case this._preBtn:
                {
                    if (this._inputTx.text == "" || this._inputTx.text == Language.getString(70162)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(70166));
                        return;
                    }
                    this.createTooltip();
                    break;
                }
                case this._craveBtn:
                {
                    if (this._inputTx.text == "" || this._inputTx.text == Language.getString(70162)) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(70166));
                        return;
                    }
                    loc1 = Cache.instance.role.money.gold;
                    if (this._neetCost > loc1) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(70316));
                        return;
                    }
                    loc2 = !PulseSharedObject.isTodayNotTips("mountCrave");
                    if (loc2) 
                    {
                        Alert.alertWinRenderer = CheckBoxWin;
                        Alert.show(Language.getStringByParam(70174, this._inputTx.text, this._neetCost), null, Alert.OK | Alert.CANCEL, null, this.onBtnClickHandler);
                    }
                    else 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.MountGoCrave, {"itemData": _curIdata, "content": this._inputTx.text, "fontColor": _curColorNum, "lightColor": _curGlowNum}));
                    }
                    break;
                }
            }
            return;
        }

        /* internal  */reflashTooltip(): void
        {
            var loc1=null;
            var loc2=null;
            if (MountCraveWindow._toolTip) 
            {
                loc1 = new ItemData(this._curIdata.itemCode);
                loc2 = new ItemExInfo();
                loc2 = this._curIdata.itemExInfo.duplicate();
                loc2.m_mark = [[this._curIdata.itemExInfo.model_id, 1, this._inputTx.text, this._curColorNum, this._curGlowNum]];
                loc1.itemExInfo = loc2;
                MountCraveWindow._toolTip.data = loc1.getToolTipData(ItemData.ToolTipType_Mounts);
            }
            return;
        }

        /* internal  */createTooltip(): void
        {
            var loc1=new ItemData(this._curIdata.itemCode);
            var loc2=new ItemExInfo();
            loc2 = this._curIdata.itemExInfo.duplicate();
            loc2.m_mark = [[this._curIdata.itemExInfo.model_id, 1, this._inputTx.text, this._curColorNum, this._curGlowNum]];
            loc1.itemExInfo = loc2;
            if (!MountCraveWindow._toolTip) 
            {
                MountCraveWindow._toolTip = new Tooltip();
                MountCraveWindow._toolTip.mouseEnabled = false;
                MountCraveWindow._toolTip.mouseChildren = false;
                MountCraveWindow._closeBtn = ObjCreate.createGButton("", MountCraveWindow._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                MountCraveWindow._spTooltipContainer.addChild(MountCraveWindow._toolTip);
                MountCraveWindow._spTooltipContainer.mouseEnabled = false;
                MountCraveWindow._spTooltipContainer.addChild(MountCraveWindow._closeBtn);
            }
            MountCraveWindow._toolTip.data = loc1.getToolTipData(ItemData.ToolTipType_Mounts);
            MountCraveWindow._closeBtn.x = MountCraveWindow._toolTip.width - 24;
            MountCraveWindow._closeBtn.configEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            addChild(MountCraveWindow._spTooltipContainer);
            MountCraveWindow._spTooltipContainer.x = -30;
            MountCraveWindow._spTooltipContainer.y = -30;
            return;
        }

        /* internal  */onBtnClickHandler(arg1: int, arg2: Boolean): void
        {
            if (arg1 == Alert.OK) 
            {
                Alert.resetToDefault();
                Dispatcher.dispatchEvent(new DataEvent(EventName.MountGoCrave, {"itemData": _curIdata, "content": this._inputTx.text, "fontColor": _curColorNum, "lightColor": _curGlowNum}));
            }
            if (arg2) 
            {
                PulseSharedObject.save("mountCrave", true);
            }
            return;
        }

        /* internal  */resetToolTipPosition(): void
        {
            return;
        }

        protected closeTootipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (MountCraveWindow._spTooltipContainer && MountCraveWindow._spTooltipContainer.parent) 
            {
                MountCraveWindow._spTooltipContainer.parent.removeChild(MountCraveWindow._spTooltipContainer);
            }
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._stRoundBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.mountCraveMark);
            return;
        }

        public setData(arg1: ItemData): void
        {
            this._curIdata = arg1;
            this._baseIteam.itemData = this._curIdata;
            this._txCost.text = Language.getString(70167) + Cache.instance.pack.mountsPackCache.getCurCost(this._curIdata);
            this._neetCost = Cache.instance.pack.mountsPackCache.getNeedYB(this._curIdata);
            return;
        }

        
        {
            MountCraveWindow._spTooltipContainer = new Object /* flash.display.Sprite */();
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(16, 40, 298, 182, this);
            this._baseIteam = new BaseItem();
            this._baseIteam.x = 130;
            this._baseIteam.y = 89;
            this._baseIteam.setSize(58, 58);
            this._baseIteam.isShowToolTip = false;
            addChild(this._baseIteam);
            var loc1=new Object /* flash.display.Shape */();
            loc1.graphics.beginFill(16777215);
            loc1.graphics.drawCircle(158, 118, 29);
            loc1.graphics.endFill();
            addChild(loc1);
            this._baseIteam.mask = loc1;
            this._stRoundBm = ObjCreate.createBitmap("", 80, 46, this);
            this._txCost = ObjCreate.createTextField("", 214, 44, 102, 22, this, new GTextFormat(FontUtil.songtiName, 13, 15788607));
            this._stxWordColor = ObjCreate.createTextField(Language.getString(70160), 214, 72, 62, 22, this, new GTextFormat(FontUtil.songtiName, 13, 15788607));
            this._stxGlowColor = ObjCreate.createTextField(Language.getString(70161), 214, 100, 62, 22, this, new GTextFormat(FontUtil.songtiName, 13, 15788607));
            var loc2=ObjCreate.createGButton("", 278, 70, 25, 23, this, "ColorSelector");
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onColorBtnClickHandler);
            var loc3=ObjCreate.createGButton("", 278, 98, 25, 23, this, "ColorSelector");
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onGlowBtnClickHandler);
            this._colorPanel = new MountCraveColorPicker();
            this._colorPanel.x = 247;
            this._colorPanel.y = -39;
            this._colorPanel.visible = false;
            this._colorPanel.addEventListener(EventName.ChatColorSelect, this.onColorSelectHandler);
            addChild(this._colorPanel);
            this._glowPanel = new MountCraveColorPicker();
            this._glowPanel.x = 247;
            this._glowPanel.y = -15;
            this._glowPanel.visible = false;
            this._glowPanel.addEventListener(EventName.ChatColorSelect, this.onGloweelectHandler);
            addChild(this._glowPanel);
            this._inputTx = new GTextInput();
            this._inputTx.styleName = "GTextInput";
            this._inputTx.textField.selectable = true;
            this._inputTx.maxChars = 10;
            this._inputTx.setSize(227, 25);
            this._inputTx.move(54, 159);
            addChild(this._inputTx);
            this._inputTx.text = Language.getString(70162);
            this._inputTx.styleName = "GTextInput";
            this._inputTx.drawNow();
            this._inputTx.setStyle("textFormat", FriendStyle.textFormatOffline);
            this._preBtn = ObjCreate.createGButton(Language.getString(70163), 76, 190, 68, 25, this);
            this._craveBtn = ObjCreate.createGButton(Language.getString(70164), 190, 190, 68, 25, this);
            this._preBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClick);
            this._craveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClick);
            this._txDec = ObjCreate.createTextField("", 17, 223, 295, 84, this);
            var loc4;
            this._txDec.multiline = loc4 = true;
            this._txDec.wordWrap = loc4;
            this._txDec.htmlText = "<textFormat leading=\'5\'>" + HTMLUtil.addColor(Language.getString(70165), "#00ff00") + "<br>" + HTMLUtil.addColor(PublicMessageConfig.instance.getMountModuleTextByName("MountCrave") + "</textFormat>", GlobalStyle.color1);
            LoaderHelp.addResCallBack(ResFileConst.mount, this.onLoadBmResource);
            this._inputTx.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.changeSearchHandler);
            this._inputTx.addEventListener(flash.events.FocusEvent.FOCUS_OUT, this.changeSearchHandler);
            this._inputTx.addEventListener(flash.events.Event.CHANGE, this.onInputChange);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            return;
        }

        protected onColorSelectHandler(arg1: DataEvent): void
        {
            this._curColorNum = Cache.instance.pack.mountsPackCache.getCraveColorNum(arg1.data as uint);
            this._inputTx.textField.textColor = arg1.data as uint;
            this.reflashTooltip();
            return;
        }

        /* internal */ /* var */_stRoundBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_baseIteam: BaseItem;

        /* internal */ /* var */_curIdata: ItemData;

        /* internal */ /* var */_preBtn: GButton;

        /* internal */ /* var */_craveBtn: GButton;

        /* internal */ /* var */_txCost: Object /* flash.text.TextField */;

        /* internal */ /* var */_stxWordColor: Object /* flash.text.TextField */;

        /* internal */ /* var */_stxGlowColor: Object /* flash.text.TextField */;

        /* internal */ /* var */_colorPanel: MountCraveColorPicker;

        /* internal */ /* var */_glowPanel: MountCraveColorPicker;

        /* internal */ /* var */_curColorNum: uint=1;

        /* internal */ /* var */_curGlowNum: uint=4;

        /* internal */ /* var */_neetCost: int;

        /* internal */ /* var */_inputTx: GTextInput;

        /* internal */ /* var */_txDec: Object /* flash.text.TextField */;

        /* internal */ static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_closeBtn: GButton;

        /* internal */ static /* var */_toolTip: Tooltip;
    }
